﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace PictureBoard4.Shape
{
    /// <summary>
    /// 三角形
    /// </summary>
   public class Triangle:Shape
    {
       //
        public Point StartPoint { get; set; }
        public Point EndPoint { get; set; }
        public override void Add(System.Drawing.Point p)
        {
            if (StartPoint == EndPoint)
                StartPoint = p;
            else
                EndPoint = p;
        }

        public override bool GetBound(ref System.Drawing.Point StartPoint, ref System.Drawing.Point EndPoint)
        {
            StartPoint = this.StartPoint;
            EndPoint = this.EndPoint;
            return true;
        }

        public override bool Draw(System.Drawing.Graphics g)
        {
            Point[] point = new Point[4];
            point[0].X = StartPoint.X > EndPoint.X ? (StartPoint.X - EndPoint.X) / 2 + EndPoint.X : (EndPoint.X - StartPoint.X) / 2 + StartPoint.X;
            point[0].Y = StartPoint.Y;
            point[1].X = StartPoint.X;
            point[1].Y = EndPoint.Y;
            point[2] = EndPoint;
            point[3].X = StartPoint.X > EndPoint.X ? (StartPoint.X - EndPoint.X) / 2 + EndPoint.X : (EndPoint.X - StartPoint.X) / 2 + StartPoint.X;
            point[3].Y = StartPoint.Y;
            g.DrawPolygon(new Pen(Tool.SColor, Tool.SWidth), point);
            return true;
        }

        public override void Move(System.Drawing.Point point)
        {
            if (point.X != 0)
            {
                Point TempStartPoint = StartPoint;
                Point TempEndPoint = EndPoint;

                StartPoint = new Point(TempStartPoint.X + point.X, TempStartPoint.Y + point.Y);
                EndPoint = new Point(TempEndPoint.X + point.X, TempEndPoint.Y + point.Y);
            }
        }
    }
}
